home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
s-gikan2.maizuru-ct.ac.jp
/
s-gikan2.maizuru-ct.ac.jp.zip
/
s-gikan2.maizuru-ct.ac.jp
/
pub
/
old
/
ncvc350_install.exe
/
{app}
/
scripts
/
decycle_G82.pl
< prev
next >
Wrap
Perl Script
|
2004-04-01
|
5KB
|
190 lines
#! /usr/bin/perl
# G82é≡æ╝é╠NCâRü[âhé╔ò╧è╖é╖éΘâXâNâèâvâg #
$pre_file= $ARGV[0];
$out_file= $ARGV[1];
open(IN,$pre_file);
open(OUT,">$out_file");
$initZ= 0;
$kotei_flag= 0;
$G82_flag= 0;
$i= 0; # âRâüâôâgùpò╧Éö
$G98G99= "G98";
while(<IN>){
if(!/^N?[0-9\s]*[\(\%]/){
if(/G92/){
if(/Z([\-\d\.]+)/){ $absoZ= $1; }
}
if(/G90/ or /G91/){ $G90G91= $&; }
if(/G98/ or /G99/){ $G98G99= $&; }
if($kotei_flag == 1){
$kotei_flag= koteiCycle_cancel($_);
if($kotei_flag == 0){ $absoZ= $initZ; }
}
else{ $kotei_flag= koteiCycle_start($_); }
if($G82_flag == 1){ $G82_flag= G82_cancel($_); }
$initZ= $absoZ;
if(/G82/){
$G82_flag= 1;
if(/[KL]([\d]+)/){ $kurikaeshi_suu= $1; }
else{ $kurikaeshi_suu= 1; }
if(/G90/ or /G91/){ print OUT $&."\n"; }
if(/G98/ or /G99/){ print OUT $&."\n"; }
while(/[SM][\d\.]+/g){ print OUT $&."\n"; }
@G82cycle= ();
($XY_move,$Z_move)= ("","");
### 1 XüCYì└òWæüæùéΦô«ì∞
if(/[XY]/){
$XY_move= "G00";
while(/[XY][\-\d\.]+/g){ $XY_move= $XY_move.$&; }
$XY_move= $XY_move."\n";
}
### 2 Rô_É┌ï▀ô«ì∞
if(/R([\-\d\.]+)/){
$R= $1; #Rô_ò£ïAùpò╧Éö
$Z_move= "G00Z".$R."\n";
}
else{ undef($R); }
### 3 îèèJé»ô«ì∞
if(/Z([\-\d\.]+)/){
$kirikomiZ= $1; #É╪éΦì₧é▌É[é│ùpò╧Éö
if(/F[\d\.]+/){ push(@G82cycle,"G01Z".$kirikomiZ.$&."\n"); }
else{ push(@G82cycle,"G01Z".$kirikomiZ."\n"); }
}
### 4 âhâEâFâïô«ì∞
if(/P[\d\.]+/){ push(@G82cycle,"G04".$&."\n"); }
### éT Zì└òWò£ïAô«ì∞
## G90é╠é╞é½
## G98é╚éτâCâjâVâââïô_é╔üAG99é╚éτRô_é╔û▀éΘ
if($G90G91 eq "G90"){
if($G98G99 eq "G98"){ push(@G82cycle,"G00Z".$initZ."\n"); }
else{
push(@G82cycle,"G00Z".$R."\n");
$initZ= $R;
}
}
## G91é╠é╞é½
## æOƱé╞é╡é─$RüA$kirikomiZé═â}âCâiâXé╠ÆlüB2,3é╠ìsÆ÷é┼èiö[ì╧é▌
## G99é╠é╞é½é═Rô_é╔û▀éΘé╠é┼üAÉ╪éΦì₧é±é╛Zé╠ê┌ô«ù╩é╛é»ÅπÅ╕é╖éΩé╬éµéó
## G98é╠é╞é½é═âCâjâVâââïô_é╔û▀éΘé╠é┼üAÉ╪éΦì₧é±é╛Zé╠ê┌ô«ù╩é╞üA
## Rô_é¬éáé┴é╜ÅΩìçé═üARô_é▄é┼é╠ê┌ô«ù╩é╛é»é│éτé╔ÅπÅ╕
else{
$kirikomiZ =~ s/-//;
## G98é╠é╞é½é═âCâjâVâââïô_é▄é┼ÅπÅ╕
if($G98G99 eq "G98"){
if(/R/){
if($R =~ /-/){ $return_R= $'; }
$kirikomiZ= marume($kirikomiZ,$return_R);
}
push(@G82cycle,"G00Z".$kirikomiZ."\n");
}
## G99é╠é╞é½é═É╪éΦì₧é±é╛ò¬é╛é»ÅπÅ╕üARô_é≡ïLë»
else{
push(@G82cycle,"G00Z".$kirikomiZ."\n");
if(/R/){ $initZ= marume($initZ, $R); }
}
}
for($j=1;$j<=$kurikaeshi_suu;$j++){
$i++;
print OUT "(Drilling Cycle $i)\n";
print OUT $XY_move;
if($j == 1){ print OUT $Z_move; }
elsif($G98G99 eq "G98" and defined($R)){ print OUT "G00Z".$R."\n"; }
foreach (@G82cycle){
print OUT;
}
}
}
else{
if($G82_flag == 1 and /[XY][\d\-\.\s]+/){
$XY_move= "";
while(/[XY][\d\.\-]+/g){
$XY_move= $XY_move.$&;
$_= $`.$';
}
if(!/[N\d\s]/){ print OUT;}
$i++;
print OUT "(Drilling Cycle $i)\n";
print OUT "G00".$XY_move."\n";
if($G98G99 eq "G98" and defined($R)){ print OUT "G00Z".$R."\n"; }
foreach (@G82cycle){
print OUT;
}
}
else{
## G82âéü[âhé┼é╚éóÅΩìçüAé╗é╠é▄é▄Åoù═
print OUT;
### âCâjâVâââïô_ïLë»ùpé╠Åêù¥
## G90é╠é╞é½
if($G90G91 eq "G90"){
## G99é╠é╞é½é═Rô_é╔û▀éΘ
if($G98G99 eq "G99"){
if(/R([\-\d\.]+)/){ $initZ= $1; }
}
## G98é¬éáéΘé╞é½é╠Zé╠ăé╠ÉöÄÜé═É╪éΦì₧é▌é╠É[é│é┼éáé┴é─üAò£ïAé╖éΘì└òWé┼é═é╚éó
## G98é┼é═âCâjâVâââïô_üAé┬é▄éΦé╗éΩê╚æOé╔ê┌ô«é╡é╜Zì└òWé╔ò£ïAé╖éΘé╠é┼$initZé≡ò╧ìXé╖éΘòKùvé═é╚éó
## éµé┴é─üAé╗éΩê╚èOé╠Ä₧é╠Zé╠ê┌ô«ì└òWé≡è─Äïé╖éΘ
else{
if(/Z([\-\d\.]+)/){ $initZ= $1; }
}
}
## G91é╠é╞é½é═é╗é╠ôsôxé╠æèæ╬ù╩é┼æ╬Åêé┼é½éΘé¬üAôrÆåé┼G91é⌐éτG90é╔ê┌ìsé╡é╜ÅΩìçüAÉΓæ╬ì└òWé¬ò¬é⌐éτé╚é¡é╚éΘüB
## é╗é▒é┼üAZé╠ÉΓæ╬ì└òWé≡ê┌ô«é╠æèæ╬ù╩é┼öcê¼é╡é─é¿é¡òKùvé¬éáéΘ
else{
if($G98G99 eq "G99"){
if(/R([^A-Z\s]+)/){ $initZ= marume($initZ, $1); }
}
else{
if(/Z([^A-Z\s]+)/){ $initZ= marume($initZ, $1); }
}
}
}
}
}
else{ print OUT; }
}
close(OUT);
close(IN);
sub marume{
my ($num1,$num2,$enzanshi) = @_;
my $num;
$num1 *= 1000;
$num2 *= 1000;
$num1= int($num1);
$num2= int($num2);
if($enzanshi eq '-'){ $num= ($num1 - $num2) / 1000; }
else{ $num= ($num1 + $num2) / 1000; }
if($num !~ /\./ and $num != 0){ $num= $num."\."; }
return $num;
}
sub koteiCycle_start{
($_)= @_;
if(/G7[346]/ or /G8[1-9]/){ return 1; }
else{ return 0; }
}
sub koteiCycle_cancel{
($_)= @_;
if(/G80/ or /G0*[0123][A-Z\s]/ or /G33/){ return 0; }
else{ return 1;}
}
sub G82_cancel{
($_)= @_;
if(/G7[346]/ or /G8[013-9]/ or /G0*[0123][A-Z\s]/ or /G33/){ return 0; }
else{ return 1; }
}